/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.inse6260.atms.model;

/**
 *
 * @author seif
 */
public class Transfer implements Transaction
{
    private int srcAcc;
    private int tgtAcc;
    private float transferAmount;

    private BankDatabase bankDatabase;

    /**
     * Instantiates transfer object with accountNumber and amount
     * @param accountNumber BankClient account number
     * @param transferAmount transfer amount
     */
    public Transfer(BankDatabase bankDatabase, int srcAcc, int tgtAcc, float transferAmount)
    {
        // initialize fields
        this.srcAcc = srcAcc;
        this.tgtAcc = tgtAcc;
        this.transferAmount = transferAmount;
        this.bankDatabase = bankDatabase;
    }

    /**
     * Executes transaction
     */
    public void execute()
    {
        bankDatabase.insertTransLineItem(tgtAcc, "credit", transferAmount);
        bankDatabase.credit(tgtAcc, transferAmount);

        bankDatabase.insertTransLineItem(srcAcc, "debit", transferAmount);
        bankDatabase.debit(srcAcc, transferAmount);
    }
}
